package org.ben.iotest;

public class Solution {
    public int solution(int[] A) {
        long sumN = 0L;
        long sumP = 0L;
        for(int p = 0 ; p < A.length; p++) {
            if(0 == p) {
                sumP = 0;
            }
            int k = p + 1;
            if (1 == k) {
                for (; k < A.length; k++)
                    sumN += A[k];
            }
            if(sumP == sumN)
                System.out.println(p);

            System.out.println(p+ " , " + k + " , " + sumP + " , " + sumN);
            if(A.length == p+1)
                sumN = 0;
            else
                sumN -= A[p+1];
            sumP += A[p];
        }
        return -1;
    }

    int steps=0;
    void steps(String s) {
        if("" != s && (Integer.parseInt(s) == 0)) {
            System.out.println(s);
            return;
        }
        steps++;
        if(s.endsWith("1")) {
            s = s.substring(0, s.length() - 1).concat("0");
            System.out.println(s);
            steps(s);
        } else {
            s = s.substring(0,s.length()-1);
            System.out.println(s);
            steps(s);
        }
    }

    public int solution(String S) {
        steps(S);
        return steps;
    }

    int nodeN=0;
    void visibleNodes(Tree t, int max) {
        if(t.x > max) {
            nodeN++;
            max = t.x;
            System.out.println(nodeN + " , " + max);
        }
        if(t.l == null)
            return;
        else
            visibleNodes(t.l,max);
        if(t.r == null)
            return;
        else
            visibleNodes(t.r,max);
    }
    public int solution(Tree T) {
        visibleNodes(T,T.x);
        return nodeN;
    }

    class Tree {
        public int x;
        public Tree l;
        public Tree r;
    }

    public String solution(int N, String S, String T) {
        String[] p1 = S.split(",")[0].split(" ");
        String[] p2 = S.split(",")[1].split(" ");
        String[] t = T.split(" ");
        int topR = Integer.parseInt(p1[0].split("[A-Z]")[0]);
        int botR = Integer.parseInt(p1[1].split("[A-Z]")[0]);
        int topC = (int)p1[0].split("[0-9]+")[1].charAt(0);
        int botC = (int)p1[1].split("[0-9]+")[1].charAt(0);
        String[][] s1 = new String[((botR-topR)+1)][((botC-topC)+1)];
        int topR1 = Integer.parseInt(p2[0].split("[A-Z]")[0]);
        int botR1 = Integer.parseInt(p2[1].split("[A-Z]")[0]);
        int topC1 = (int)p2[0].split("[0-9]+")[1].charAt(0);
        int botC1 = (int)p2[1].split("[0-9]+")[1].charAt(0);
        String[][] s2 = new String[((botR1-topR1)+1)][((botC1-topC1)+1)];
        for(int i = 0; i < s1.length; i++) {
            for(int j = 0; j < s1[i].length; j++) {
                String s = (topR+j) + "";
                s1[i][j] = s.concat((char)(topC+j) +  "");
                System.out.println(s1[i][j]);
            }
        }
        for(int i = 0; i < s2.length; i++) {
            for(int j = 0; j < s2[i].length; j++) {
                String s = (topR1+j) + "";
                s2[i][j] = s.concat((char)(topC1+j) +  "");
                System.out.println(s2[i][j]);
            }
        }
        int sunkN = 0;
        for (int i = 0; i < s1.length; i++) {
            for (int j = 0; j < s1[i].length; j++) {
                for (int k = 0; k < t.length; k++) {
                    System.out.println(s1[i][j] + " , " + t[k]);
                    if (s1[i][j].equals(t[k]))
                        sunkN++;
                }
            }
        }
        int sunkN1 = 0;
        for (int i = 0; i < s2.length; i++) {
            for (int j = 0; j < s2[i].length; j++) {
                for (int k = 0; k < t.length; k++) {
                    System.out.println(s2[i][j] + " , " + t[k]);
                    if (s2[i][j].equals(t[k]))
                        sunkN1++;
                }
            }
        }
        System.out.println(s1.length + " , " + sunkN + " , " + s2.length + " , " + sunkN1);
        int sunkR = 0;
        String result = "";
        if(s1.length == sunkN) {
            System.out.println("sunked 1");
            sunkR++;
            result += "0,1";
        }
        if(s2.length == sunkN1) {
            sunkR++;
            System.out.println("sunked 2");
        }
        if(1 == sunkR)
            return "1,1";
        else if( 2 == sunkR)
            return "0,2";
        else 
            return "2,0";
    }
    
    public static void main(String[] args) {
//        int a[] = new int[]{-1,3,-4,5,1,-6,2,1};
//        new Solution().solution(a);
//        System.out.println(new Solution().solution("011100"));
        new Solution().solution(0,"1A 2A,12A 12A","12A");
//        System.out.println("1A".split("[0-9]+")[1]);
    }
}
